# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/9 19:22
# @Author   : Robot-Zsj
"""
description:

input
3 3
0 0 0
0 1 0
0 0 0
output
2
"""
n, m = map(int, input().split())
matrix = [list(map(int, input().split())) for _ in range(n)]


def getResult():
    if matrix[0][0] == 1 or matrix[n - 1][m - 1] == 1:
        return 0

    dp = [[0 for _ in range(m)] for _ in range(n)]
    dp[0][0] = 1

    for i in range(n):
        for j in range(m):
            if matrix[i][j] == 1:
                continue
            if i > 0:
                dp[i][j] += dp[i - 1][j]
            if j > 0:
                dp[i][j] += dp[i][j - 1]
    return dp[n - 1][m - 1]


print(getResult())
